package stackQueue;

public class Exam3_2_1 {
	public static void main(String[] args) {
		char[] input = { '[', '(', ')', ']', '{', '(', '}', ')' };
		char[] stack = new char[input.length];

		int topOfStack = -1;
		int result = 0;

		for (int i = 0; i < input.length; i++) {
			switch (input[i]) {
			case '[':
			case '{':
			case '(':
				Stack_321.push(stack, ++topOfStack, input[i]);
				break;
			default:
				if (topOfStack == -1) {
					result++;
					break;
				} else {
					char top = Stack_321.pop(stack, topOfStack--);
					if ((input[i] == ')' && top != '(')
							|| (input[i] == ']' && top != '[')
							|| (input[i] == '}' && top != '{')) {
						result++;
					}
					break;
				}
			}
		}
		if (topOfStack > -1) {
			System.out.println("false dd");
		} else if (result == 0) {
			System.out.println("true " + result);
		} else if (result > 0) {
			System.out.println("false rr " + result);
		}

	}
}

class Stack_321 {

	public static void push(char[] arr, int topOfStack, char x) {
		arr[topOfStack] = x;
	}

	public static char pop(char[] arr, int topOfStack) {
		char x = arr[topOfStack];
		return x;
	}

}
